<?php
namespace common\models\order;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\enums\StatusEnum;
use common\helpers\RegularHelper;

/**
 * This is the model class for table "{{%order_goods}}".
 *
 */
class OrderGoods extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%order_goods}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['order_id','goods_id','goods_price','goods_num','goods_pay_price','store_id','buyer_id'], 'required'],
            [['order_id','goods_id','goods_num','store_id','buyer_id','promotions_id','commis_rate'], 'integer'],
            [['goods_price','goods_pay_price'], 'number'],
            [['goods_name'], 'string', 'max' => 50],
            [['goods_image'],'string','max'=>100],
            ['goods_type','string']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'rec_id' => 'ID',
            'order_id' => '订单id',
            'goods_id'=>'商品id',
            'goods_name' => '商品名称',
            'goods_price' => '商品价格',
            'goods_num' => '商品数量',
            'goods_image' => '商品图片',
            'goods_pay_price' => '商品实际成交价',
            'store_id' => '店铺ID',
            'buyer_id' => '买家ID',
            'goods_type' => '购买类型',//1默认2团购商品3限时折扣商品4组合套装5赠品
            'promotions_id' => '促销活动ID',//促销活动ID（团购ID/限时折扣ID/优惠套装ID）与goods_type搭配使用
            'commis_rate'=>'佣金比例',

        ];
    }

    /**
     * 场景
     *
     * @return array
     */
    public function scenarios()
    {
        return [
//            'backendCreate' => ['goods_name', 'goods_code','goods_bar','goods_unit','gc_id','member_id','store_id'],
            'default' => array_keys($this->attributeLabels()),
        ];
    }


    /**
     * @return array
     */
//    public function behaviors()
//    {
//        return [
//            [
//                'class' => TimestampBehavior::class,
//                'attributes' => [
//                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
//                ],
//            ],
//        ];
//    }
}
